package models.frame;

import java.util.*;

import javax.persistence.*;

import models.pubobj.*;

import com.avaje.ebean.validation.*;

import play.db.ebean.Model;

@Entity
public class AniMenuObj extends Model{

	@Id
	public Long id;
	
	@NotNull
	public String objKey;
	
	public String controller;

	public String method;
	
	@NotNull
	public AniObjectState state;
	
	@ManyToOne
	public AniMenuObj parent;
	
	@OneToMany(mappedBy = "parent")
	public List<AniMenuObj> subObjects;
	
	public AniMenuObj(){}
	
	public AniMenuObj(Long id, String objKey, String controller, String method,
			AniObjectState state, AniMenuObj parent) {
		super();
		this.id = id;
		this.objKey = objKey;
		this.controller = controller;
		this.method = method;
		this.state = state;
		this.parent = parent;
	}

	public static Model.Finder<Long, AniMenuObj> find = new Finder<
			Long, 
			AniMenuObj>(Long.class, AniMenuObj.class);
	
	public static List<AniMenuObj> rootMenuObjects(){
		return find.where().eq("parent", null).findList();
	}

    public static List<AniMenuObj> allMenuObjects(){
        return find.all();
    }
}